package nci60.data.maxquant.peptide
import nci60.data.maxquant.Experiment
import nci60.data.maxquant.Project

/**
 * Information about the identified peptides for each cell line (experiment) <p />
 * (source: peptides.txt)
 *
 * @autor <a href="mailto:Florian.J.Auer@googlemail.com">Florian J. Auer</a>
*/
class PeptideExperiment {

    /**
    * Reference to the cell line (experiment) this peptide information belongs to <p />
    * @see nci60.data.maxquant.Experiment
    */
    Experiment experiment
    
    /**
    * number of evidences for this peptide
    */
    Integer numberOfEvidences
    
    /**
    * number of unique evidences for this peptide
    */
    Integer numberOfUniqueEvidences
    
    /**
    * total intensity of all the isotopic patterns in this label cluster associated with the identified AA sequence
    */
    Double intensity
    
    /**
    * reference to the analysis it belongs to <p />
    * @see nci60.data.maxquant.Project
    */
    Project currentProject

    /**
    * GRAILS <a href="http://grails.org/doc/latest/guide/GORM.html#gormAssociation" target="_blank">Associations in Gorm</a>
    * <p />
    * <style>.custom-table td{border-top:1pt solid grey;vertical-align:top;} .custom-table{border-collapse:collapse;width:100%;}</style>
    * <table class="custom-table">
    * <tr><td>
    *              peptide
    * </td><td>        belongs to one specific peptide entry<p />
    *                  <b>See Also:</b> {@link nci60.data.maxquant.peptide.Peptide}
    * </td></tr>
    * </table>
    */
    static belongsTo = [peptide:Peptide]

    /**
     * GRAILS <a href="http://grails.org/doc/latest/guide/single.html#constraints" target="_blank">Declaring Constraints</a>
     * <p />
     * Constraints in Grails are a way to declaratively specify validation rules for generating objects in GORM.
     */	
    static constraints = {
    }

    /**
     * Transforms the attribute values from the MaxQuant input file to values suitable for sql. e.g. "+", and "", are converted into "true", and "false" respectively. <p />
     * This mehtod is used while importing new data.
     * 
     * @param property  name of the property of this class (specified above)
     * @param input     attribute value in the MaxQuant output file
     * @return  replaced sql value of the input
     */	
    static String modifySQL(String property, String input) {
        String output
        if((property=='onlyIdentifiedBySite')||(property=='reverse')||(property=='contaminant')){
            if(input=='+'){
                output = '1'
            }else{
                output = '0'
            }
        }else if((property=='numberOfEvidences')||(property=='numberOfUniqueEvidences')){
            if(input==''){
                output = '0'
            }else{
                output = input
            }
        }else{
            output = input
        }
        return output
    }
}
